$(function() {

    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.iframeAuto(index);

    $(".select-item-materialBom").on("click", function() {
        var id = $(this).data("id");
        if (parent.layui.$("input[name='materialIds'][value='" + id + "']").size() == 0) {
            var unitName = $(this).data("unitname");
            var str = '<tr><td><input type="hidden" name="materialIds" value="' + id + '" />' + $(this).data('code') + '</td><td>';
            str += $(this).data('name') + '</td><td>' + unitName + '</td>';
            str += '<td><input type="text" name="materialScale" autocomplete="off" class="layui-input" style="width: 100px; display: inline-block" />' + $(this).data("unitstr") + '</td>';
            str += '<td><a href="javascript:void(0);" class="layui-btn layui-btn-xs layui-btn-danger hidden-xs delete-row" id="' + id + '"><i class="layui-icon">&#xe640;</i></a></td></tr>';
            parent.layui.$("#itemTable").append(str);
        } else {
            parent.layer.tips("已选择", ".delete-row[id='" + id + "']", {
                time : 3000
            });
        }
        parent.layer.close(index);
    });

    $(".select-item-halfMaterialBom").on("click", function() {
        var id = $(this).data("id");
        if (parent.layui.$("input[name='materialIds'][value='" + id + "']").size() == 0) {
            var unitName = $(this).data("unitname");
            var str = '<tr><td><input type="hidden" name="materialIds" value="' + id + '" />' + $(this).data('code') + '</td><td>';
            str += $(this).data('name') + '</td><td>' + unitName + '</td>';
            str += '<td><input type="text" name="materialScale" autocomplete="off" class="layui-input" style="width: 100px; display: inline-block" />' + $(this).data("unitstr") + '</td>';
            str += '<td><a href="javascript:void(0);" class="layui-btn layui-btn-xs layui-btn-danger hidden-xs delete-row" id="' + id + '"><i class="layui-icon">&#xe640;</i></a></td></tr>';
            parent.layui.$("#itemTable").append(str);
        } else {
            parent.layer.tips("已选择", ".delete-row[id='" + id + "']", {
                time : 3000
            });
        }
        parent.layer.close(index);
    });

});